package com.catchu.pattern.creational.迭代器模式.b进阶;

import com.catchu.pattern.creational.迭代器模式.b进阶.aggregate.ArrayPayAggregate;
import com.catchu.pattern.creational.迭代器模式.b进阶.aggregate.ListPayAggregate;
import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.ArrayPayIterator;
import com.catchu.pattern.creational.迭代器模式.b进阶.iterator.Iterator;

public class Client {
    public static void main(String[] args) {
        ListPayAggregate listPayAggregate = new ListPayAggregate();
        listPayAggregate.calcPay();
        Iterator iterator = listPayAggregate.createIterator();
        test(iterator);

        System.out.println("========分隔符=========");

        ArrayPayAggregate arrayPayAggregate = new ArrayPayAggregate();
        arrayPayAggregate.calcPay();
        ArrayPayIterator iterator2 = new ArrayPayIterator(arrayPayAggregate);
        test(iterator2);
    }

    public static void test(Iterator iterator){
        iterator.first();
        while (!iterator.isDone()){
            System.out.println( iterator.currentItem());
            iterator.next();
        }
    }
}
